<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
            width: 100px;
            height:30px;
            text-align: center;
            line-height: 30px;
        }
        div:nth-of-type(1){
            background-color: red;
            text-align: center;
        }
        div:nth-of-type(2){
            background-color: orange;
        }
        div:nth-of-type(3){
            background-color: yellow;
        }
        div:nth-of-type(4){
            background-color: green;
        }
        div:nth-of-type(5){
            background-color: aqua;
        }
    </style>
</head>
<body>
<div>一</div>
<div>二</div>
<div>三</div>
<div>四</div>
<div>五</div>
</body>
<script>
    let divs=document.getElementsByTagName("div");
    for (let i=0;i<divs.length;i++){
        divs[i].onclick=function () {
            alert(divs[i].innerHTML);
        }
    }
</script>
</html>